package com.wangyadong.hobby.schedule.jobtask.springresource;

import org.springframework.core.io.Resource;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

public class UrlResource {

    public static void main(String[] args) throws IOException {
        fileResource(args);
        System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
    }


    public static void fileResource(String[] args) throws IOException {
        org.springframework.core.io.UrlResource urlResource = new org.springframework.core.io.UrlResource("file:C:\\java\\Data Structures and Algorithms in Java 6th Edition.2014.pdf");
        toString(urlResource);
    }

    public static void httpResource(String[] args) throws IOException {
        org.springframework.core.io.UrlResource urlResource = new org.springframework.core.io.UrlResource("file:C:\\java\\Data Structures and Algorithms in Java 6th Edition.2014.pdf");
        toString(urlResource);
    }

    public static void toString(Resource resource) throws IOException {

        System.out.println("  Filename " + resource.getFilename() + "  " + resource.getURI().toString() + "  getURL " +
                resource.getURL().toString() + " inputStream " + resource.getInputStream());
    }
}
